package com.tony.easymvc;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import com.google.common.io.LineReader;

/**
 * 模板加载
 * 
 * @author zhangruiyu tonyruiyu@163.com
 * @date 2017年6月16日 下午2:52:29
 * @since V1.0
 * @version V1.0
 */
public class TemplateUtils {

    public static String loadTempl(String name) throws IOException {
    	try {
        StringBuilder context = new StringBuilder("");
        InputStream is = TemplateUtils.class.getClassLoader().getResourceAsStream(name);
        LineReader lr = new LineReader(new InputStreamReader(is,"utf-8"));
        String line = null;
        while ((line = lr.readLine()) != null) {
            context.append(line).append("\r\n");
        }
        is.close();
        return context.toString();
    	}catch (Exception e) {
    		throw new RuntimeException(" the resources : " + name + " not found", e);
		}
    }

    public static void main(String[] args) throws IOException {
    	
        String s = TemplateUtils.loadTempl("tmpl/p_pom.tmpl");
        System.out.println(s);
    }
}
